<!DOCTYPE html>
<html>
        <head>
        <title>Page Title</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
        <script type="text/javascript" src="../js/jquery.mobile.router.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
        <script type="text/javascript">
	var router=new $.mobile.Router([
		{ "#localpage2(?:[?/](.*))?": {handler: "localpageA", events: "bc,c,i"} },
		{ "#localpage2(?:[?/](.*))?": {handler: "localpageB", events: "bs,s"} },
		{ "#localpage2(?:[?/](.*))?": {handler: "localpageC", events: "bh,h"} },
		{ "#index": { handler: function(type){
				console.log("Index has been "+(type=="pagehide"?"hidden":"shown"));
			}, events: "h,s" }
		}
	],{
                localpageA: function(type,match,ui){
			var params=router.getParams(match[1]);
			console.log("localpage function A: "+type);
			console.log(params);
                },
                localpageB: function(type,match,ui){
			var params=router.getParams(match[1]);
			console.log("localpage function B: "+type);
			console.log(params);
                },
                localpageC: function(type,match,ui){
			var params=router.getParams(match[1]);
			console.log("localpage function C: "+type);
			console.log(params);
                }
	},{ 
		defaultHandler: function(type, ui, page) {
			console.log("Default handler called due to unknown route (" 
				+ type + ", " + ui + ", " + page + ")");
		},
		defaultHandlerEvents: "s"
	});

        setTimeout(function(){
        	alert("adding a dynamic route to localpage3...");
		router.add([
			{ "#localpage3(?:[?/](.*))?": {handler: "localpage3Shown", events: "s"} },
			{ "#localpage3(?:[?/](.*))?": {handler: "localpage3Hidden", events: "h"} }
		],{
	 		localpage3Shown: function(type,match){
				var params=router.getParams(match[1]);
				console.log("localpage3 shown");
				console.log(params);
		    	},
	 		localpage3Hidden: function(type,match){
				var params=router.getParams(match[1]);
				console.log("localpage3 hidden");
				console.log(params);
		    	}
		});
        },20000);

	setTimeout(function(){
		alert("deactivating router...");
		router.destroy();
	},120000);
        </script>
</head>

<body>

<div data-role="page" id="index">
        <div data-role="header">
                <h1>Index</h1>
        </div>

        <div data-role="content">
                <p>Page 1</p>
                <p>The output of this page can be seen in your javascript console.</p>
                <p>
                        <a href="#localpage2?param=value&param2=value">#localpage2 with params v1 (classic)</a><br/>
                        <a href="#localpage2?foo=bar&bar=foo&foobarbaz">#localpage2 with params v2 (classic)</a><br/>
                        The following route will be enabled after 20seconds<br/>
                        <a href="#localpage3?blablah=blohblohbloh">#localpage3 with params</a><br/>
                </p>
        </div>

        <div data-role="footer">
                <h4>Index footer</h4>
        </div>
</div>


<div data-role="page" id="localpage2" data-add-back-btn="true">
        <div data-role="header">
                <h1>Localpage 2</h1>
        </div>

        <div data-role="content">
                <p>This is the localpage 2 in the multipage template.</p>
                <p><a href="#index">Back to index</a></p>
        </div>

        <div data-role="footer">
                <h4>Localpage 2 Footer</h4>
        </div>
</div>

<div data-role="page" id="localpage3" data-add-back-btn="true">
        <div data-role="header">
                <h1>Localpage 3</h1>
        </div>

        <div data-role="content">
                <p>This is the localpage 3 in the multipage template.</p>
                <p><a href="#index">Back to index</a></p>
        </div>

        <div data-role="footer">
                <h4>Localpage 3 Footer</h4>
        </div>
</div>

</body>

</html>
